<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="Webpixels">
    <title>Quick – Website UI Kit (FREE)</title>
    <!-- Preloader -->
    <style>
        @keyframes hidePreloader {
            0% {
                width: 100%;
                height: 100%;
            }

            100% {
                width: 0;
                height: 0;
            }
        }

        body>div.preloader {
            position: fixed;
            background: white;
            width: 100%;
            height: 100%;
            z-index: 1071;
            opacity: 0;
            transition: opacity .5s ease;
            overflow: hidden;
            pointer-events: none;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        body:not(.loaded)>div.preloader {
            opacity: 1;
        }

        body:not(.loaded) {
            overflow: hidden;
        }

        body.loaded>div.preloader {
            animation: hidePreloader .5s linear .5s forwards;
        }
    </style>
    <script>
        window.addEventListener("load", function() {
            setTimeout(function() {
                document.querySelector('body').classList.add('loaded');
            }, 300);
        });
    </script>
    <!-- Favicon -->
    <link rel="icon" href="../static/img/favicon.ico" type="image/png"><!-- Font Awesome -->
    <link rel="stylesheet" href="../static/css/all.min.css">
    <!-- Quick CSS -->
    <link rel="stylesheet" href="../static/css/quick-website.css" id="stylesheet">
</head>

<body>
<!-- Main content -->
<section>
    <div class="container d-flex flex-column">
        <div class="row align-items-center justify-content-center min-vh-100">
            <div class="col-md-6 col-lg-5 col-xl-5 py-6 py-md-0">
                <div class="card shadow zindex-100 mb-0">
                    <div class="card-body px-md-5 py-5">
                        <div class="mb-5">
                            <h6 class="h3">更新</h6>
                            <p class="text-muted mb-0">修改信息</p>
                        </div>
                        <span class="clearfix"></span>
                        <form id="registerForm">
                            <div class="form-group">
                                <label class="form-control-label">用户名</label>
                                <div class="input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i data-feather="users"></i></span>
                                    </div>
                                    <input readonly type="text" class="form-control" id="username" placeholder="输入您的用户名">
                                </div>
                            </div>
                            <div class="form-group mb-0">
                                <div class="d-flex align-items-center justify-content-between">
                                    <div>
                                        <label class="form-control-label">密码</label>
                                    </div>
                                </div>
                                <div class="input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i data-feather="key"></i></span>
                                    </div>
                                    <input type="text" class="form-control" id="password" placeholder="输入您的密码">
                                </div>
                            </div>
                            <div class="form-group mb-0">
                                <div class="d-flex align-items-center justify-content-between">
                                    <div>
                                        <label class="form-control-label">邮箱</label>
                                    </div>
                                </div>
                                <div class="input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i data-feather="key"></i></span>
                                    </div>
                                    <input type="email" class="form-control" id="email" placeholder="输入您的邮箱">
                                </div>
                            </div>
                            <div class="form-group mb-0">
                                <div class="d-flex align-items-center justify-content-between">
                                    <div>
                                        <label class="form-control-label">电话</label>
                                    </div>
                                </div>
                                <div class="input-group">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text"><i data-feather="key"></i></span>
                                    </div>
                                    <input type="text" class="form-control" id="phone" placeholder="输入您的电话号码">
                                </div>
                            </div>
                            <div class="mt-4">
                                <button type="submit" class="btn btn-block btn-primary">注册</button></div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
<!-- Core JS  -->
<script src="../static/js/jquery.min.js"></script>
<script src="../static/js/bootstrap.bundle.min.js"></script>
<script src="../static/js/svg-injector.min.js"></script>
<script src="../static/js/feather.min.js"></script>
<!-- Quick JS -->
<script src="../static/js/quick-website.js"></script>
<!-- Feather Icons -->
<script>
    feather.replace({
        'width': '1em',
        'height': '1em'
    })
</script>

<script>
    $(function () {
        $('#registerForm').on('submit', function (event) {
            event.preventDefault();

            var formData = {
                username: $('#username').val(),
                password: $('#password').val(),
                email: $('#email').val(),
                phone: $('#phone').val()
            };

            $.ajax({
                type: 'POST',
                url: '/users/api/update',
                data: JSON.stringify(formData),
                contentType: 'application/json',
                dataType: 'json',
                success: function (response) {
                    // 检查服务器返回的状态码
                    console.log(response.code,response.msg)
                    if (response.code === 200) {
                        // 根据消息判断是否注册成功
                        if (response.msg === "Success") {
                            alert('修改成功');
                            window.location.href = '/users/update';
                        } else {
                            alert(response.message);
                        }
                    } else {
                        alert(response.message || '修改失败，请稍后再试。');
                    }
                },
                error: function (xhr, status, error) {
                    console.error('Error:', error);
                    alert('An error occurred during registration.');
                }
            });
        });
    });

    function fetchUsername() {
        // 假设这是您的API URL
        const url = '/users/api/getname';

        fetch(url)
            .then(response => response.json())  // 解析JSON数据
            .then(data => {
                if (data && data.data) {
                    document.getElementById('username').value = data.data;
                } else {
                    console.error('未找到用户名');
                }
            })
            .catch(error => {
                console.error('获取用户名失败:', error);
            });
    }

    $(function(){
        fetchUsername();
    })
</script>
</body>

</html>